import BaseView from "../baseView.js";

export default class addschedules extends BaseView {
  render() {
    $("#Content").html(`
         <div>
         <div style="margin: 30px 10px 0 20px ">
         <span class="layui-breadcrumb" style="visibility: visible;">
             <a>学生管理系统/</a>/
             <a>学生资料管理/</a>/
             <a>添加学生</a>
          </span>
          <hr/>
         </div>
         <div>
         <form class="layui-form">
         <div class="layui-form-item">
         <label class="layui-form-label">电影名:</label>
           <div class="layui-input-block">
             <input type="text" id="movieId" required   placeholder="请输入电影名"  class="layui-input">
           </div>
         </div>
         <div class="layui-form-item">
         <label class="layui-form-label">影院名:</label>
           <div class="layui-input-block">
             <input type="text" id="cinemasId" required   placeholder="请输入影院名"  class="layui-input">
           </div>
         </div>
         <div class="layui-form-item">
         <label class="layui-form-label">放映厅:</label>
           <div class="layui-input-block">
             <input type="text" id="theaterId" required   placeholder="请输入放映厅名"  class="layui-input">
           </div>
         </div>

         <div class="layui-inline">
         <label class="layui-form-label">日期时间选择器</label>
         <div class="layui-input-inline">
           <input type="text" class="layui-input" id="showTime"  required placeholder="2021-10-23 小时:分钟:秒">
         </div>
       </div>


       <!-- 注释
         <div class="layui-form-item">
         <label class="layui-form-label">放映时间:</label>
           <div class="layui-input-block">
             <input type="text" id="showTime" required   placeholder="请输入放映时间"  class="layui-input">
           </div>
         </div>
          -->


         <div class="layui-form-item">
         <label class="layui-form-label">价格:</label>
           <div class="layui-input-block">
             <input type="text" id="price" required   placeholder="请输入价格"  class="layui-input">
           </div>
         </div>
         <div class="layui-form-item">
           <div class="layui-input-block">
             <button type='button' id='addstudentBtn' class="layui-btn" lay-submit lay-filter="formDemo">添加</button>
             <button type="reset" class="layui-btn layui-btn-primary" id="chongzhi">重置</button>
             <button type="reset" class="layui-btn layui-btn-primary" id="back">返回</button>
           </div>
         </div>
       </form>
         </div>
         
         </div>
        `)
  }
  handle() {



    $("#addLayuijs").html(`
       <script>
        layui.use('form', function(){
        var form = layui.form;
         //重新渲染表单
         form.render();
        });
        //日期时间选择器
        layui.use('laydate', function(){
        var laydate = layui.laydate;
        laydate.render({
        elem: '#showTime',
        type: 'datetime'
         });
        })
        </script>
         `)

    //绑定添加事件
    $("#addstudentBtn").click(() => {
      $.ajax({
        type: "post",
        url: "/schedules/addSchedules",
        data: {
          "movieId": $("#movieId").val(),
          "cinemasId": $("#cinemasId").val(),
          "theaterId": $("#theaterId").val(),
          "showTime": $("#showTime").val(),
          "price": $("#price").val()
        },
        dataType: "json",
        success: (data) => {
          console.log(data)
          if (data.code == 1) {
            alert(data.msg);
            window.location.hash = "#/main/schedulesList";
          } else {
            alert(data.msg);
          }
        }
      })
    })

    $("#back").click(() => {
      window.location.hash = "#/main/schedulesList";
    })

    $("#chongzhi").click(() => {
      // 清空表单数据
      $("#addGoodsForm")[0].reset();
      layui.form.render();
    })

  }
}